package com.lehuowujie.lehuomarket.fragment;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.lehuowujie.lehuomarket.R;
import com.lehuowujie.lehuomarket.adapter.CategoryLeftAdapter;
import com.lehuowujie.lehuomarket.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 分类
 * Created by 王瑞铭 on 2017/1/13.
 */
public class CategoryFragment extends BaseFragment {

    public static final String TAG = CategoryFragment.class.getName();

    public static CategoryFragment mFragment;

    public static CategoryFragment getInstance() {
        if (mFragment == null) {
            synchronized (CategoryFragment.class) {
                if (mFragment == null)
                    mFragment = new CategoryFragment();
            }
        }
        return mFragment;
    }

    private ListView mListView;
    private CategoryLeftAdapter leftAdapter;
    private List<String> mList = new ArrayList<>();

    @Override
    public int createView() {
        return R.layout.fragment_category;
    }

    @Override
    public void initView() {
        initToolBar();
        setTitle(R.string.fragment_category);
        mListView = (ListView) mContentView.findViewById(R.id.listView);
        setListData();
        leftAdapter = new CategoryLeftAdapter(getActivity(),mList);
        mListView.setAdapter(leftAdapter);
    }

    @Override
    public void initEvent() {
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                leftAdapter.setSelectPosition(i);
                leftAdapter.notifyDataSetChanged();
            }
        });
    }

    private void setListData() {
        mList.clear();
        mList.add("推荐分类");
        mList.add("潮流女装");
        mList.add("品牌男装");
        mList.add("个护化妆");
        mList.add("家用电器");
        mList.add("电脑办公");
        mList.add("手机数码");
        mList.add("母婴童装");
        mList.add("图书音像");
        mList.add("家居家纺");
        mList.add("家居生活");
        mList.add("家居建材");
        mList.add("食品生鲜");
        mList.add("酒水饮料");
        mList.add("运动户外");
        mList.add("鞋靴箱包");
        mList.add("奢品礼品");
        mList.add("钟表珠宝");
        mList.add("玩具乐器");
        mList.add("内衣配饰");
        mList.add("汽车用品");
        mList.add("医药保健");
        mList.add("计生情趣");
        mList.add("全球购");
        mList.add("京东金融");
        mList.add("生活旅行");
        mList.add("宠物农资");
    }
}
